from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from selenium.webdriver.support.select import Select
d=webdriver.Firefox()
d.get('file:///E:/%E8%93%AC%E8%8E%B1%E5%B0%8F%E8%AF%BE2024%E6%B5%8B%E8%AF%95/%E7%AC%AC%E5%9B%9B%E9%98%B6%E6%AE%B5/Selenium%E8%87%AA%E5%8A%A8%E5%8C%96/selenium_demo/day03demo/message.html')
data={
    "name":"san",
    "psw":123,
    "email":"123099@123.com",
    "message":"test",

}
locator={
    #"name":"input[id='un']",
    "name":"#un",
    "psw":"input#pw",
    "sex":"input#male",
    "sex":"input#female",
    "email":"input[name='email']",
    "profession":"//select[@name='profession']",
    "message":"textarea[name=textfield]",
    "computer":"input[value='computer']",
    "film": "input[value='film']",
    "chess": "input[value='chess']",
    "read": "input[value='read']",
    "food": "input[value='food']",
    "painting": "input[value='painting']",
    "submit":'#sub',
    "reset":"input[type=reset]"
}
list=[By.XPATH,By.CSS_SELECTOR]
myname=d.find_element_by_css_selector(locator["name"])
myname.send_keys(data["name"])
sleep(2)
mypsd=d.find_element_by_css_selector(locator["psw"])
mypsd.send_keys(data["psw"])
sleep(2)
mysex=d.find_element_by_css_selector(locator["sex"])
mysex.click()
sleep(2)
myemail=d.find_element_by_css_selector(locator["email"])
myemail.send_keys(data["email"])
sleep(2)
myprofession=d.find_element_by_xpath(locator['profession'])
s1=Select(myprofession)
s1.select_by_index(1)
sleep(2)
mycomputer=d.find_element(list[1],locator['computer'])
mycomputer.click()
mychess=d.find_element(list[1],locator['chess'])
mychess.click()
mypainting=d.find_element(list[1],locator['painting'])
mypainting.click()
sleep(2)
myemail=d.find_element(list[1],locator['message'])
myemail.send_keys(data['message'])
sleep(2)
mysubmit=d.find_element(list[1],locator['submit'])
mysubmit.click()
myreset=d.find_element(list[1],locator['reset'])
myreset.click()
#d.quit()


